//
//  M_MineHelpZXViewController.m
//  Model
//
//  Created by apple on 2018/7/14.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "M_MineHelpZXViewController.h"
#import "XHChatQQ.h"
@interface M_MineHelpZXViewController ()
{
    UIView *vipView;//vip弹窗
}
@property (nonatomic, strong) UIButton *qqButton;
@property (nonatomic, strong) UIButton *weiXinButton;
@property (nonatomic, strong) UILabel *titLab;

@end

@implementation M_MineHelpZXViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    
    
}
//电池颜色
- (UIStatusBarStyle)preferredStatusBarStyle{
    
    return UIStatusBarStyleLightContent;
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self creationView];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
}
- (void)creationView{
    
    UIImageView *beiJingImgView = [[UIImageView alloc] init];
    UIImage *beiJingImg = [UIImage imageNamed:@"bg_head_logo"];
    [self.view addSubview:beiJingImgView];
    [beiJingImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view);
        make.left.equalTo(self.view);
        make.right.equalTo(self.view);
        make.height.offset(beiJingImg.size.height);
        
    }];
    beiJingImgView.userInteractionEnabled = YES;
    
    beiJingImgView.image =beiJingImg;
    UIButton *backButton = [[UIButton alloc] init];
    [beiJingImgView addSubview:backButton];
    [backButton setBackgroundImage:[UIImage imageNamed:@"return"] forState:UIControlStateNormal];
    [backButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).with.offset((KIsiPhoneX?60:38));
        make.left.equalTo(self.view).with.offset(13);
        make.width.offset(screenScale(25));
        make.height.offset(screenScale(25));
    }];
    [backButton addTarget:self action:@selector(leftNavItemClick) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *titleLab = [[UILabel alloc] init];
    [beiJingImgView addSubview:titleLab];
    titleLab.text = @"帮助中心";
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.centerY.equalTo(backButton);
    }];
    titleLab.textColor = [UIColor whiteColor];
    titleLab.font = [UIFont systemFontOfSize:17];
    
    self.qqButton = [[UIButton alloc] init];
    [self.view addSubview:self.qqButton];
    UIImage *qqImg = [UIImage imageNamed:@"icon_qq_p"];
    [self.qqButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.view);
        make.left.equalTo(self.view).with.offset(80);
        make.width.offset(qqImg.size.width);
        make.height.offset(qqImg.size.height);
        
    }];
    [_qqButton setBackgroundImage:qqImg forState:UIControlStateNormal];
    [self.qqButton addTarget:self action:@selector(qqClick) forControlEvents:UIControlEventTouchUpInside];
    UILabel *qqLab = [[UILabel alloc] init];
    [self.view addSubview:qqLab];
    [qqLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.qqButton.mas_bottom).with.offset(10);
        make.centerX.equalTo(self.qqButton);
        
    }];
    qqLab.text = @"QQ客服";
    qqLab.textColor = getColor(@"ff40c6");
    qqLab.font = [UIFont systemFontOfSize:16];
    
    
    
    self.weiXinButton = [[UIButton alloc] init];
    [self.view addSubview:self.weiXinButton];
    UIImage *weiXinImg = [UIImage imageNamed:@"icon_wechat_p"];
    [self.weiXinButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.view);
        make.right.equalTo(self.view).with.offset(-80);
        make.width.offset(weiXinImg.size.width);
        make.height.offset(weiXinImg.size.height);
        
    }];
    [_weiXinButton setBackgroundImage:weiXinImg forState:UIControlStateNormal];
    [self.weiXinButton addTarget:self action:@selector(weiXinClick) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *weiXinLab = [[UILabel alloc] init];
    [self.view addSubview:weiXinLab];
    [weiXinLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.weiXinButton.mas_bottom).with.offset(10);
        make.centerX.equalTo(self.weiXinButton);
        
    }];
    weiXinLab.text = @"微信客服";
    weiXinLab.textColor = getColor(@"ff40c6");
    weiXinLab.font = [UIFont systemFontOfSize:16];
    
    UILabel *phoneLab = [[UILabel alloc] init];
    [self.view addSubview:phoneLab];
    [phoneLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view).with.offset(-16);
        make.centerX.equalTo(self.view);
        
        
    }];
    phoneLab.text = @"客服电话: ";
    phoneLab.textColor = getColor(@"818181");
    phoneLab.font = [UIFont systemFontOfSize:12];
    
    UILabel *timeLab = [[UILabel alloc] init];
    [self.view addSubview:timeLab];
    [timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(phoneLab.mas_top).with.offset(-12);
        make.centerX.equalTo(self.view);
        
        
    }];
    timeLab.text = @"工作时间: 周一到周日(8:00 ~ 16:00)";
    timeLab.textColor = getColor(@"818181");
    timeLab.font = [UIFont systemFontOfSize:12];
    
    
    
}
//////返回
- (void)leftNavItemClick{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}

// QQ客服
- (void)qqClick{
    //是否安装QQ
    
    if([XHChatQQ haveQQ])
        
    {
    //        //传入用来接收临时消息的QQ号码
    //        //调用QQ客户端,发起QQ临时会话
        
        [XHChatQQ chatWithQQ:@"1459814487"];
        
    }else{
        
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"请安装QQ" preferredStyle:(UIAlertControllerStyleAlert)];
        
        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:nil];
        [alert addAction:cancel];
        [self showDetailViewController:alert sender:nil];
 
    }
}
//微信
- (void)weiXinClick{
    
    vipView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT)];
    vipView.backgroundColor = [UIColor colorWithRed:0 / 255.0f green:0 / 255.0f blue:0 / 255.0f alpha:0.2];
    
    [[UIApplication sharedApplication].keyWindow addSubview:vipView];
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissVIPView)];
    [vipView addGestureRecognizer:tapGesture];
    UIView *bangView = [[UIView alloc] init];
    [vipView addSubview:bangView];
    [bangView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).with.offset((KIsiPhoneX?84:64)+180);
        make.height.offset(150);
        make.left.equalTo(self.view).with.offset(24);
        make.right.equalTo(self.view).with.offset(-24);
        
    }];
    bangView.backgroundColor = [UIColor whiteColor];
    bangView.layer.cornerRadius = 5;
    _titLab = [[UILabel alloc] init];
    [bangView addSubview:_titLab];
    [_titLab mas_makeConstraints:^(MASConstraintMaker *make) {
        //        make.top.equalTo(bangView).with.offset(70);
        make.centerX.equalTo(bangView);
        make.centerY.equalTo(bangView);
    }];
    //    titLab.text = @"加入VIP会员才可以观看专享";
    _titLab.text = @"客服 18968154907";
    _titLab.textColor = getColor(@"818181");
    _titLab.font = [UIFont systemFontOfSize:16];
    
    _titLab.userInteractionEnabled = YES;
    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPre:)];
    [_titLab addGestureRecognizer:longPress];
    
    
    UIButton *xButton = [[UIButton alloc] init];
    [xButton setBackgroundImage:[UIImage imageNamed:@"icon_x"] forState:UIControlStateNormal];
    [bangView addSubview:xButton];
    [xButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bangView);
        make.right.equalTo(bangView);
    }];
    [xButton addTarget:self action:@selector(dismissVIPView)forControlEvents:UIControlEventTouchUpInside];
    
    
}

- (BOOL)canBecomeFirstResponder{
    return YES;
}
// 可以控制响应的方法
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender{
    return (action == @selector(copy:));
}
//针对响应方法的实现，最主要的复制的两句代码
- (void)copy:(id)sender{
    
    //UIPasteboard：该类支持写入和读取数据，类似剪贴板
    UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
    pasteBoard.string = self.titLab.text;
}
// 处理长按事件
- (void)longPre:(UILongPressGestureRecognizer *)recognizer{
    [self becomeFirstResponder]; // 用于UIMenuController显示，缺一不可
    
    //UIMenuController：可以通过这个类实现点击内容，或者长按内容时展示出复制等选择的项，每个选项都是一个UIMenuItem对象
    UIMenuItem *copyLink = [[UIMenuItem alloc] initWithTitle:@"复制" action:@selector(copy:)];
    [[UIMenuController sharedMenuController] setMenuItems:[NSArray arrayWithObjects:copyLink, nil]];
    [[UIMenuController sharedMenuController] setTargetRect:self.titLab.frame inView:self.titLab.superview];
    [[UIMenuController sharedMenuController] setMenuVisible:YES animated:YES];
    
}
- (void)dismissVIPView{
         
    
    [vipView removeFromSuperview];
         
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
